import { ADMIN_API } from '@/services/admin/typings'

/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(initialState: { userinfo: ADMIN_API.UserInfoVO } | undefined) {
  const { userinfo } = initialState ?? {}
  let permList = userinfo?.perm || []
  let roleList = userinfo?.role || []
  return {
    canAdmin: permList.includes('admin'),
    setting: permList.includes('setting'),
    hasUserPerm: permList.includes('user:menu'),
    hasUserSavePerm: permList.includes('user:save'),
    hasUserUpdatePerm: permList.includes('user:update'),
    hasUserRemovePerm: permList.includes('user:remove'),
    hasPermPerm: permList.includes('perm:menu'),
    hasPermSavePerm: permList.includes('perm:save'),
    hasPermUpdatePerm: permList.includes('perm:update'),
    hasPermRemovePerm: permList.includes('perm:remove'),
    hasRolePerm: permList.includes('role:menu'),
    hasRoleSavePerm: permList.includes('role:save'),
    hasRoleUpdatePerm: permList.includes('role:update'),
    hasRoleRemovePerm: permList.includes('role:remove'),
    hasGeneratePerm: permList.includes('generate:menu'),
    hasTestPerm: permList.includes('test:menu'),
    hasTestSavePerm: permList.includes('test:save'),
    hasTestUpdatePerm: permList.includes('test:update'),
    hasTestRemovePerm: permList.includes('test:remove'),
    hasCustomerPerm: permList.includes('customer:menu'),
    hasCustomerSavePerm: permList.includes('customer:save'),
    hasCustomerUpdatePerm: permList.includes('customer:update'),
    hasCustomerRemovePerm: permList.includes('customer:remove'),
    hasCustomerChannelPerm: permList.includes('customerChannel:menu'),
    hasCustomerChannelSavePerm: permList.includes('customerChannel:save'),
    hasCustomerChannelUpdatePerm: permList.includes('customerChannel:update'),
    hasCustomerChannelRemovePerm: permList.includes('customerChannel:remove'),
    hasDictDataPerm: permList.includes('dictData:menu'),
    hasDictDataSavePerm: permList.includes('dictData:save'),
    hasDictDataUpdatePerm: permList.includes('dictData:update'),
    hasDictDataRemovePerm: permList.includes('dictData:remove'),
    hasDictTypePerm: permList.includes('dictType:menu'),
    hasDictTypeSavePerm: permList.includes('dictType:save'),
    hasDictTypeUpdatePerm: permList.includes('dictType:update'),
    hasDictTypeRemovePerm: permList.includes('dictType:remove'),
    hasGoodsPerm: permList.includes('goods:menu'),
    hasGoodsSavePerm: permList.includes('goods:save'),
    hasGoodsUpdatePerm: permList.includes('goods:update'),
    hasGoodsRemovePerm: permList.includes('goods:remove'),
    hasOrderPerm: permList.includes('order:menu'),
    hasOrderSavePerm: permList.includes('order:save'),
    hasOrderUpdatePerm: permList.includes('order:update'),
    hasOrderRemovePerm: permList.includes('order:remove'),
    hasMarketingPerm: permList.includes('marketing:menu'),
    hasFormPerm: permList.includes('form:menu'),
    hasTargetPerm: permList.includes('target:menu'),
    hasTargetSavePerm: permList.includes('target:save'),
    hasTargetUpdatePerm: permList.includes('target:update'),
    hasTargetRemovePerm: permList.includes('target:remove'),
    hasNotifyPerm: permList.includes('notify:menu'),
    hasNotifySavePerm: permList.includes('notify:save'),
    hasNotifyUpdatePerm: permList.includes('notify:update'),
    hasNotifyRemovePerm: permList.includes('notify:remove'),
    hasSettingPerm: permList.includes('setting:menu'),
    hasSettingSavePerm: permList.includes('setting:save'),
    hasSettingUpdatePerm: permList.includes('setting:update'),
    hasSettingRemovePerm: permList.includes('setting:remove'),
    hasAutoReplyPerm: permList.includes('autoReply:menu'),
    hasAutoReplySavePerm: permList.includes('autoReply:save'),
    hasAutoReplyUpdatePerm: permList.includes('autoReply:update'),
    hasAutoReplyRemovePerm: permList.includes('autoReply:remove'),
    hasSocialUserPerm: permList.includes('socialUser:menu'),
    hasSocialUserSavePerm: permList.includes('socialUser:save'),
    hasSocialUserUpdatePerm: permList.includes('socialUser:update'),
    hasSocialUserRemovePerm: permList.includes('socialUser:remove'),
    hasActivityPerm: permList.includes('activity:menu'),
    hasActivitySavePerm: permList.includes('activity:save'),
    hasActivityUpdatePerm: permList.includes('activity:update'),
    hasActivityRemovePerm: permList.includes('activity:remove'),
    hasActivityAwardPerm: permList.includes('activityAward:menu'),
    hasActivityAwardSavePerm: permList.includes('activityAward:save'),
    hasActivityAwardUpdatePerm: permList.includes('activityAward:update'),
    hasActivityAwardRemovePerm: permList.includes('activityAward:remove'),
    hasPosterPerm: permList.includes('poster:menu'),
    hasPosterSavePerm: permList.includes('poster:save'),
    hasPosterUpdatePerm: permList.includes('poster:update'),
    hasPosterRemovePerm: permList.includes('poster:remove'),
    hasInfraFilePerm: permList.includes('infraFile:menu'),
    hasInfraFileSavePerm: permList.includes('infraFile:save'),
    hasInfraFileUpdatePerm: permList.includes('infraFile:update'),
    hasInfraFileRemovePerm: permList.includes('infraFile:remove'),
    hasMpPerm: permList.includes('mp:menu'),
    hasMpSavePerm: permList.includes('mp:save'),
    hasMpUpdatePerm: permList.includes('mp:update'),
    hasMpRemovePerm: permList.includes('mp:remove'),

    hasAdminRole: roleList.includes('tenant-admin'),
    hasSupervisorRole: roleList.includes('supervisor'),
    hasSellerRole: roleList.includes('seller'),
    hasDeveloperRole: roleList.includes('developer'),
  }
}
